import { useWarningNotice } from '@u/notice.js';
import { createRouter, createWebHashHistory } from 'vue-router'
import { routes } from './route.js';

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach(to => {
  // const token = localStorage.getItem('token')
  // const isInManageRouteGroup = /^Mange(?!(Login))/.test(to.name)
  // const isToLogin = !token && isInManageRouteGroup
  // if (isToLogin) {
  //   useWarningNotice({
  //     message: '无此权限，请先登录'
  //   })
  //   return { name: 'ManageLogin' }
  // }
  // return true;
  const token = localStorage.getItem('token')
  const isInManageRouteGroup = /^Manage(?!(Login))/.test(to.name)
  const isToLogin = !token && isInManageRouteGroup
  if (isToLogin) {
    useWarningNotice({
      message: "无此权限，请先登录"
    })
    return { name: 'ManageLogin' }
  }
  return true;
})

export default router
